package com.csoa.community.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.collect.community.R;
import com.csoa.community.bean.AreaBean;
import com.csoa.community.utils.AndroidUtils;

public class AreaAdapter extends BaseAdapter {

	private Context activity;
	private List<AreaBean> areaBeans;

	public AreaAdapter(Context activity, List<AreaBean> officialDocs) {
		this.activity = activity;
		this.areaBeans = officialDocs;
	}

	@Override
	public int getCount() {
		return areaBeans == null ? 0 : areaBeans.size();
	}

	@Override
	public AreaBean getItem(int arg0) {
		return areaBeans == null ? null : areaBeans.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = null;
		ViewHolder holder = null;
		if (null == convertView) {
			holder = new ViewHolder();
			view = AndroidUtils.inflateView(activity, R.layout.item_area_issue, null);
			holder.areaName = (TextView) view.findViewById(R.id.tvAreaItem);
			holder.check = (CheckBox) view.findViewById(R.id.checkAreaItem);
			view.setTag(holder);
		} else {
			view = convertView;
			holder = (ViewHolder) view.getTag();
		}

		final AreaBean areaBean = getItem(position);
		if (areaBean != null) {
			holder.areaName.setText(areaBean.areaName);
			holder.check.setChecked(areaBean.isChecked);

		}
		holder.check.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				areaBean.isChecked = ((CheckBox) v).isChecked();
				AreaAdapter.this.notifyDataSetChanged();
			}
		});
		
//		final CheckBox check = holder.check;
//		view.setOnClickListener(new View.OnClickListener() {
//
//			@Override
//			public void onClick(View v) {
//				areaBean.isChecked = (check.isChecked());
//				AreaAdapter.this.notifyDataSetChanged();
//			}
//		});
		
		
		return view;
	}
	
	

	public final class ViewHolder {

		public TextView areaName;
		public CheckBox check;

	}

}
